package com.chaopei.day09;

/**
 * @Author Corday 天涯
 * @Date 2022/3/15 10:57
 * 创建存款子线程类,也就是生产者角色
 */
public class ProduceThread implements Runnable {
    //声明共享的帐户对象
    private Account acc;

    public ProduceThread(Account acc) {
        this.acc = acc;
    }

    @Override
    public void run() {
        go();
    }//run

    public void go() {
        //具体实现存款操作
        for (int i = 0; i < 10; i++) {
            int temp = (int)(Math.random()*60)+40;
            acc.saveMoney(temp);
            try {
                Thread.sleep((int)(Math.random()*50)+100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }//go
}
